import { queryIncidence, queryFire, queryAlarmDistribution, queryAlarmTotal, queryAlarmTrend } from './service';

export default {
	namespace: 'analyse_alarm',

	state: {
		incidence: [],
		fire: {}
	},

	effects: {
		*queryIncidence(_, { call, put }) {
			const response = yield call(queryIncidence);
			yield put({ type: 'setIncidence', payload: Array.isArray(response) ? response : [] });
		},
		*queryFire(_, { call, put }) {
			const response = yield call(queryFire);
			yield put({ type: 'setFire', payload: response });
    },
    //报警时段分布
		*queryAlarmDistribution({payload}, { call, put }) {
			const response = yield call(queryAlarmDistribution, payload);
			yield put({ type: 'setAlarmDistribution', payload: response });
    },
    //设备状态报警占比
		*queryAlarmTotal({payload}, { call, put }) {
			const response = yield call(queryAlarmTotal, payload);
			yield put({ type: 'setAlarmTotal', payload: response });
		},
		//警报趋势
		*queryAlarmTrend({payload}, { call, put }) {
			const response = yield call(queryAlarmTrend, payload);
			yield put({ type: 'setAlarmTrend', payload: response });
		},
	},

	reducers: {
		setAlarmTrend(state, action) {
			return {
				...state,
				alarmTrend: action.payload
			};
		},
		setAlarmDistribution(state, action) {
			return {
				...state,
				alarmDistribution: action.payload
			};
		},
		setAlarmTotal(state, action) {
			return {
				...state,
				alarmTotal: action.payload
			};
		},

		setAlarmToday(state, action) {
			return {
				...state,
				alarmToday: action.payload
			};
		},

		setIncidence(state, action) {
			return {
				...state,
				incidence: action.payload
			};
		},

		setFire(state, action) {
			return {
				...state,
				fire: action.payload
			};
		}
	}
};
